package com.cungmua.app.task;

import android.content.Context;

import com.cungmua.app.handler.BaseAuthenticatedRequestHandler;
import com.cungmua.app.handler.NewDealHandler;
import com.cungmua.app.model.request.NewDealRequest;
import com.cungmua.app.model.response.NewDealResponse;

import retrofit.RetrofitError;

/**
 * Created by kelvin.nguyen on 6/17/14.
 */
public class NewDealTask extends AuthenticatedTask<NewDealRequest, Void, NewDealResponse> {
    private final Context context;
    private final NewDealHandler handler;

    public NewDealTask(Context context, NewDealHandler handler) {
        this.context = context;
        this.handler = handler;
    }

    @Override
    protected Context getContext() {
        return context;
    }

    @Override
    protected NewDealResponse doInBackground() throws RetrofitError {
        NewDealRequest request = params[0];

        return service.getListNewDeal(request.toFieldMap());
    }

    @Override
    protected BaseAuthenticatedRequestHandler getHandler() {
        return handler;
    }

    @Override
    protected void onSuccess(NewDealResponse hotDealResponse) {
        handler.onListNewDeal(hotDealResponse);
    }
}
